package com.zide.report.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.zide.report.domain.vo.result.CommonLabelValueResultVO;
import com.zide.report.service.IIndexService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 石添
 * @date 2024/5/10 16:30
 */
@Service
public class IndexServiceImpl implements IIndexService {

    @Override
    public Map<String,String> getTopData() {

        HashMap<String, String> map = new HashMap<>();
        map.put("visitVolume","24565");
        map.put("userVolume","2145");
        map.put("articleVolume","235");
        map.put("videoVoulme","47");
        return map;
    }

    @Override
    public List<CommonLabelValueResultVO> indexService() {
        List<CommonLabelValueResultVO> result = new ArrayList<>();
        LocalDate endDate = LocalDate.now();
        String endStr = endDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        for (int i = 0; i < 7; i++) {
            LocalDate startDate = endDate.plusDays(-i);
            String startStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            CommonLabelValueResultVO item = new CommonLabelValueResultVO();
            item.setLabel(startStr);
            item.setValue(String.valueOf(RandomUtil.randomInt(1000, 4000)));
            result.add(item);
        }
        return result;
    }

    @Override
    public List<CommonLabelValueResultVO> visitFrom() {
        List<CommonLabelValueResultVO> result = new ArrayList<>();
        result.add(new CommonLabelValueResultVO("直接访问","335"));
        result.add(new CommonLabelValueResultVO("搜索引擎","605"));
        result.add(new CommonLabelValueResultVO("视频广告","165"));
        result.add(new CommonLabelValueResultVO("联盟广告","105"));
        result.add(new CommonLabelValueResultVO("渠道营销","204"));
        return result;
    }

    @Override
    public List<CommonLabelValueResultVO> articleRead() {

        List<CommonLabelValueResultVO> result = new ArrayList<>();
        LocalDate endDate = LocalDate.now();
        String endStr = endDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        for (int i = 0; i < 7; i++) {
            LocalDate startDate = endDate.plusDays(-i);
            String startStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            result.add(new CommonLabelValueResultVO(startStr,String.valueOf(RandomUtil.randomInt(1000, 4000))));
        }

        return result;
    }
}
